<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
      <title>供应商管理</title>
      <meta name="renderer" content="webkit">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<!--添加模态框-->
<div id="">
    <div id="addSupper" style="display: none;">
        <form action="" class="layui-form" lay-filter="">
            <div class="layui-form-item">
                <label class="layui-form-label">供应商名称</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="name" lay-verify="required" name="name"
                           placeholder="请输入供应商名称" type="text">
                </div>
            </div>
            <input  id="edidId" type="hidden"  name="edidId">
            <input  id="id" type="hidden"  name="id">
            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="contact" lay-verify="required" name="contact"
                           placeholder="请输入供应商联系人" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系地址</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="address" lay-verify="required" name="address"
                           placeholder="请输入供应商联系地址" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="number" lay-verify="required" name="number"
                           placeholder="请输入供应商联系电话" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="remarks" lay-verify="required" name="remarks"
                           placeholder="" type="text">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="    margin-left: 184px;">

                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="supperSub">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<blockquote class="layui-elem-quote news_search" style=" border-left: 0px solid #009688;">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" id="complain_search">
            供应商名称:
            <div class="layui-input-inline">
                <input type="text" name="name" id="name"
                       placeholder="供应商名称" autocomplete="off" class="layui-input">
            </div>

            <button id="search" class="layui-btn" lay-submit
                    lay-filter="provinceSearch">
                <i class="layui-icon">&#xe615;</i>
            </button>
        </form>
    </div>
    <table class="layui-hide" id="complainTable" lay-filter="complainList"></table>
</blockquote>

<script type="text/html" id="complain_toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
        <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="Supperdeletes">批量删除</a>
    </div>


</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script type="text/javascript" >
    layui.use(['table','layer','form','laypage'], function(){
        var table = layui.table,
            layer = layui.layer,
            form = layui.form,
            laypage = layui.laypage;

       var tableIns =  table.render({
            id:"provinceReload"
            ,elem: '#complainTable'
            ,url:'http://127.0.0.1:8005/supper/getAllBasics_supper'
            ,page: true
            ,toolbar: '#complain_toolbar'
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: 'ID', width:200, sort: true, fixed: 'left', totalRowText: '合计：'}
                ,{field: 'address', title: '联系地址', width:280}
                ,{field: 'contact', title: '联系人', width: 200, sort: true, totalRow: true}
                ,{field: 'name', title: '供应商名称', width:240, sort: true}
                ,{field: 'number', title: '联系电话', width: 260, sort: true, totalRow: true}
                ,{field: 'remarks', title: '备注', width:200}
                ,{fixed: 'right', width: 200, align:'center', toolbar: '#barDemo'}
            ]]
            ,limits: [5,10,20,50]
        });

        table.on('toolbar(complainList)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id),
                data = checkStatus.data;
            data = eval("(" + JSON.stringify(data) + ")");
            switch(obj.event) {
                case 'add':
                    $("#name").val("");
                    $("#contact").val("");
                    $("#address").val("");
                    $("#number").val("");
                    $("#remarks").val("");
                    $("#edidId").val(0);
                    $("#id").val("");
                    layer.open({
                        maxmin: true,
                        type: 1,//类型 信息
                        area: ['500px', '400px'],//定义宽和高
                        title: '添加供应商',//题目
                        shadeClose: false,//点击遮罩层关闭
                        content: $('#addSupper')//打开的模态框
                    });
                    break;
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'Supperdeletes':
                    var data = checkStatus.data;
                    var length = checkStatus.data.length;
                    //layer.alert(JSON.stringify(data));
                    if (length == 0) {
                        layer.msg("请选中要删除的行数据");
                    } else {
                        var delIndex1 =        layer.confirm('真的删除选择中这些数据么?', function (index) {
                            var params = "";
                            $.each(data, function (index, item) {
                                if (index == 0) {
                                    params += item.id+',';
                                } else {
                                    params +=  item.id+',';
                                }
                            });

                            params=params.substring(0,params.length-1);
                            $.post("http://127.0.0.1:8005/supper/deleteIds?params="+params,  function (res) {
                                tableIns.reload();
                                layer.msg("删除成功", {
                                    icon: 1
                                });
                            })
                        });
                    }
                    break;
            }
        });

        table.on('tool(complainList)', function(obj) {
            var data = obj.data;
            json = JSON.stringify(data);
            switch(obj.event) {
                case 'detail':

                    break;
                case 'edit':
                    $("#name").val(data.name);
                    $("#contact").val(data.contact);
                    $("#address").val(data.address);
                    $("#number").val(data.number);
                    $("#remarks").val(data.remarks);
                    $("#edidId").val(1);
                    $("#id").val(data.id);
                    layer.open({
                        maxmin: true,
                        type: 1,//类型 信息
                        area: ['500px', '400px'],//定义宽和高
                        title: '编辑供应商',//题目
                        shadeClose: false,//点击遮罩层关闭
                        content: $('#addSupper')//打开的模态框

                    });
                    break;
                case 'del':
                    var delIndex = layer.confirm('真的删除id为' + data.id + "的信息吗?", function(delIndex) {
                        $.ajax({
                            url: 'http://127.0.0.1:8005/supper/delsupperById?id='+data.id,
                            success: function(suc) {

                                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                    layer.close(delIndex);
                                    console.log(delIndex);
                                    layer.msg("删除成功", {
                                        icon: 1
                                    });

                            }
                        });
                        layer.close(delIndex);
                    });
                    break;
            }
        });
        //监听提交
        form.on('submit(supperSub)', function(data){
         var edC=  $("#edidId").val();
            if(edC==1){
                $.ajax({
                    url:'http://127.0.0.1:8005/supper/updateSupperById',
                    data:data.field,
                    success: function (data) {
                        layer.msg("提交成功")
                    }
                })
            }
         if(edC!=1){
             $.ajax({
                 url:'http://127.0.0.1:8005/supper/insertSupper',
                 data:data.field,
                 success: function (data) {
                     layer.msg("提交成功")
                 }
             })
            return;
         }
             layer.alert(JSON.stringify(data.field), {
                 title: '最终的提交信息'
             })






        });

        form.render();
        form.on('submit(provinceSearch)', function(data) {
            var formData = data.field;
            var serviceCode = formData.serviceCode,
                compOrder = formData.compOrder,
                compType = formData.compType,
                complainState = formData.complainState;
            table.reload('provinceReload', {
                page: {
                    curr: 1
                },

                url: 'http://127.0.0.1:8005/supper/sellName?name='+formData.name,
            });
            return false;
        });

    });
</script>


</body>
</html>
